import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:jd_flutter/pages/content/prod_content_second.dart';
import 'package:jd_flutter/pages/content/prod_content_third.dart';
import 'package:jd_flutter/widget/buy_button.dart';

import 'content/prod_content_first.dart';


class ProductContentPage extends StatefulWidget {
  const ProductContentPage({super.key});

  @override
  State<ProductContentPage> createState() => _ProductContentPageState();
}

class _ProductContentPageState extends State<ProductContentPage> {
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, designSize: const Size(750, 1334));

    return DefaultTabController(
      length: 3,
      child: Scaffold(
        appBar:PreferredSize(
          preferredSize: Size(double.infinity,80.h),
          child: AppBar(
            title: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children:[
                Container(
                  width: 450.w,
                  child: const TabBar(
                    indicatorSize: TabBarIndicatorSize.label,
                    indicatorColor: Colors.red,
                    tabs: [
                      Tab(
                        child: Text("商品"),
                      ),
                      Tab(
                        child: Text("详情"),
                      ),
                      Tab(
                        child: Text("评价"),
                      ),
                    ],
                  )
                )
              ]
            ),
            actions: [
              IconButton(onPressed: (){
                showMenu(
                  context: context, 
                  position: RelativeRect.fromLTRB(100.sw, 125.h, 0.w, 0),
                  items: [
                    const PopupMenuItem(
                      child: Row(
                        children: [
                          Icon(Icons.home),
                          Text("首页")
                        ],
                      ),
                    ),
                    const PopupMenuItem(
                      child: Row(
                        children: [
                          Icon(Icons.search),
                          Text("搜索")
                        ],
                      ),
                    )
                  ]
                );
              },
              icon: const Icon(Icons.more_horiz))
            ]
          ),
        ),
        body: Stack(
          children: [
            const TabBarView(
              children: [
                ProdContentFirst(),
                ProdContentSecond(),
                ProdContentThird(),
              ],
            ),
            Positioned(
              width: 1.sw,
              height: 80.h,
              bottom: 0,
              child: Container(
                decoration: const BoxDecoration(
                  border: Border(
                    top: BorderSide(
                      color: Colors.black26,
                      width: 1
                    )
                  )
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Container(
                      width: 100,
                      height: 80.h,
                      child: const Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Icon(Icons.shopping_cart),
                          Text("购物车")
                        ],
                      ),
                    ),
                    const Expanded(
                      flex: 1,
                      child: BuyButton(
                        color: Color.fromRGBO(253, 1, 0, 0.9),
                        text: "加入购物车"
                      )
                    ),
                    const Expanded(
                      flex: 1,
                      child: BuyButton(
                          color: Color.fromRGBO(255, 165, 0, 0.9),
                          text: "立即购买"
                      )
                    )
                  ]
                ),
              )
            )
          ],
        )
      )
    );
  }
}
